package com.techwells.learningkites.adapter;

import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.techwells.learningkites.R;
import com.techwells.learningkites.networkaccess.KitesRequestUrl;
import com.techwells.learningkites.networkservice.model.Favorite;
import com.techwells.learningkites.networkservice.model.FavoriteVideo;
import com.techwells.taco.widget.OnDeleteListioner;


public class DelSlideListAdapter extends BaseAdapter {

	private Context mContext;
	private List<FavoriteVideo> mlist = null;
	private OnDeleteListioner mOnDeleteListioner;
	private boolean delete = false;
	private BitmapUtils bitmapUtils;

	// private Button curDel_btn = null;
	// private UpdateDate mUpdateDate = null;

	public DelSlideListAdapter(Context mContext, List<FavoriteVideo> mlist) {
		this.mContext = mContext;
		this.mlist = mlist;
		bitmapUtils = new BitmapUtils(mContext);

	}

	public void setDelete(boolean delete) {
		this.delete = delete;
	}

	public boolean isDelete() {
		return delete;
	}

	public void setOnDeleteListioner(OnDeleteListioner mOnDeleteListioner) {
		this.mOnDeleteListioner = mOnDeleteListioner;
	}

	public int getCount() {

		return mlist.size();
	}

	public Object getItem(int pos) {
		return mlist.get(pos);
	}

	public long getItemId(int pos) {
		return pos;
	}

	public View getView(final int pos, View convertView, ViewGroup p) {

		final ViewHolder viewHolder;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_myfavoritelist, null);
			viewHolder = new ViewHolder();
			viewHolder.name = (TextView) convertView.findViewById(R.id.name);
			viewHolder.complete = (TextView) convertView.findViewById(R.id.complete);
			viewHolder.favoriteTime = (TextView) convertView.findViewById(R.id.favorite_time);
			viewHolder.delete_action = (TextView) convertView.findViewById(R.id.delete_action);
			viewHolder.img = (ImageView) convertView.findViewById(R.id.img);

			convertView.setTag(viewHolder);

		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		bitmapUtils.display(viewHolder.img,KitesRequestUrl.BASE_URL_IMG + mlist.get(pos).poster);
		viewHolder.name.setText(mlist.get(pos).cnName + mlist.get(pos).enName);
		if (mlist.get(pos).complete) {
			viewHolder.complete.setText("已学习");
		}else {
			viewHolder.complete.setText("未学完");
		}
		
		
		viewHolder.favoriteTime.setText("收藏于"+mlist.get(pos).favoriteTime);
		if (mlist.get(pos).learned) {
			viewHolder.complete.setVisibility(View.VISIBLE);
		}else {
			viewHolder.complete.setVisibility(View.INVISIBLE);
		}
		
		
		final OnClickListener mOnClickListener = new OnClickListener() {

			@Override
			public void onClick(View view) {
				if (mOnDeleteListioner != null)
					mOnDeleteListioner.onDelete(pos);

			}
		};
		viewHolder.delete_action.setOnClickListener(mOnClickListener);
		return convertView;
	}

	public static class ViewHolder {
		public TextView name,complete,favoriteTime;
		public TextView delete_action;
		public ImageView img;

	}

}
